package com.jims.master.modules.print.web;

import com.jims.master.common.utils.DateUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.common.web.impl.BaseDto;
import com.jims.master.modules.doctor.entity.ExamItem;
import com.jims.master.modules.doctor.entity.LabItem;
import com.jims.master.modules.doctor.entity.PatVisit;
import com.jims.master.modules.doctor.service.ExamItemService;
import com.jims.master.modules.doctor.service.LabItemService;
import com.jims.master.modules.doctor.service.PatVisitService;
import com.jims.master.modules.finance.service.InpBillDetailService;
import com.jims.master.modules.orders.service.OrdersService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/*import com.sun.javafx.sg.PGShape;*/
/**
 * Created by Administrator on 2017-04-12.
 * 护士端打印
 * @author 赵宁
 */
@Controller
@RequestMapping(value = "${adminPath}/nurse/print")
public class NursePrintController extends BaseController {
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private PatVisitService patVisitService;
    @Autowired
    private InpBillDetailService inpBillDetailService;
    @Autowired
    private LabItemService labItemService;
    @Autowired
    private ExamItemService examItemService;
    /**
     * 执行单打印
     * @param type
     * @param visitId
     * @return
     * @author 赵宁
     */
    @RequiresPermissions("user")
    @RequestMapping(value = {"perfromSinglePrint", ""})
     public String perfromSinglePrint(String type,String  visitId,Model model){
        PatVisit patVisit = patVisitService.get(visitId);
        List<BaseDto> list= ordersService.printPerformDrug(visitId,type);
        model.addAttribute("patVisit",patVisit);
        model.addAttribute("list",list);
        if ("druglist".equals(type)) {
            model.addAttribute("type", "服药单");
        } else if ("transfusfuse".equals(type)) {
            model.addAttribute("type", "输液单");
        } else if ("treatment".equals(type)) {
            model.addAttribute("type", "治疗单");
        } else if ("injection".equals(type)) {
            model.addAttribute("type", "注射单");
        }
        model.addAttribute("date",DateUtils.getDate());
        if(("treatment").equals(type)){
            return "modules/print/performSignleTreat";
        }else{
            return "modules/print/performSignleDrug";
        }
     }

    /**
     * 一日清单打印
     * @param visitId
     * @param startDate
     * @param endDate
     * @param model
     * @return
     * @author 赵宁
     */
    @RequiresPermissions("user")
    @RequestMapping(value = {"dayOfListPrint", ""})
    public String dayOfListPrint(String visitId,String startDate,String endDate,Model model){
        List<BaseDto> list= inpBillDetailService.findDetails(visitId,startDate+" 00:00:00",endDate+" 23:59:59");
        model.addAttribute("billDetails",list);
        model.addAttribute("startDate",startDate);
        model.addAttribute("endDate",endDate);
        model.addAttribute("date", DateUtils.getDate());
        return "modules/print/dayOfListPrint";
    }

    /**
     * 检验项目打印
     * @param model
     * @param applyId
     * @return
     * @author 陈涛
     */
    @RequiresPermissions("user")
    @RequestMapping(value = {"labApplyPrint", ""})
    public String labApplyPrint(Model model,String applyId,String name){
        List<LabItem> labItemList = labItemService.queryByApplyId(applyId);
        model.addAttribute("labItemList",labItemList);
        model.addAttribute("name",name);
        model.addAttribute("date", DateUtils.getDate());
        return "modules/print/labApplyPrint";
    }

    /**
     * 检查项目打印
     * @param model
     * @param applyId
     * @param name
     * @return
     */
    @RequiresPermissions("user")
    @RequestMapping(value = {"examApplyPrint", ""})
    public String examApplyPrint(Model model,String applyId,String name){
        List<ExamItem> examItemList = examItemService.findAllItems(applyId);
        model.addAttribute("examItemList",examItemList);
        model.addAttribute("name",name);
        model.addAttribute("date", DateUtils.getDate());
        return "modules/print/examApplyPrint";
    }

}
